/*
 * Copyright (C) 2008+ Spark Zheng
 *
 * src/test/test_random.c
 *
 */

#include <stdio.h>
#include <stdlib.h>

#include "timer.h"
#include "random.h"

int main(void);

int main()
{
	int i = 0;
	char test[33] = { 0 };

	dlib_rand_init();

	while (i < 100) {
		fprintf(stderr, "%d: rand %u\n", i++, dlib_rand32());
	}

	dlib_randstr(test, 32);
	fprintf(stderr, "%s\n", test);

	dlib_rand_exit();

	int array[10000];
	int array_2[3000] = { 0 };
	int array_3[10000] = { 0 };

	struct timeval start;
	struct timeval end;
	struct timeval result;

	for (i = 0; i < 10000; i++)
		array[i] = i + 1;

	dlib_rand_init();

	DLIB_UTIMER_RECORD(&start);
	dlib_random_pickup(array, 10000, array_2, 3000, sizeof (int));
	DLIB_UTIMER_RECORD(&end);
	DLIB_UTIMER_SUB(&end, &start, &result);

	fprintf(stderr, "cost time %06fs\n",
		result.tv_sec + (float) result.tv_usec / 1000000);
	for (i = 0; i < 3000; i++)
		fprintf(stderr, "%d ", array_2[i]);
	fprintf(stderr, "\n");

	DLIB_UTIMER_RECORD(&start);
	dlib_random_pickup(array, 10000, array_3, 10000, sizeof (int));
	DLIB_UTIMER_RECORD(&end);
	DLIB_UTIMER_SUB(&end, &start, &result);

	fprintf(stderr, "cost time %06fs\n",
		result.tv_sec + (float) result.tv_usec / 1000000);
	for (i = 0; i < 10000; i++)
		fprintf(stderr, "%d ", array_3[i]);
	fprintf(stderr, "\n");

	dlib_rand_exit();

	return 0;
}
